package collection;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import javax.print.DocFlavor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

public class CollectionToArray {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        Collections.addAll(c, "one", "two", "three", "four", "five");
        System.out.println(c);

        //若参数数组元素个数==集合元素个数，那就正常转换
        //若参数数组元素个数<集合元素个数，那也正常转换(按照集合大小给数组)
        //若参数数组元素个数>集合元素个数，那也正常转换，同时在末尾补默认值
        String[] array = c.toArray(new String[5]);
        System.out.println(Arrays.toString(array));

        String[] array1 = c.toArray(new String[0]);
        System.out.println(Arrays.toString(array1));

        String[] array2 = c.toArray(new String[7]);
        System.out.println(Arrays.toString(array2));
    }
}
